package springair.business.delegates.rsl 
{
	import flash.system.ApplicationDomain;
	import springair.domain.swc.RSLSWC;
	import springair.domain.swc.digest.RSLLibrary;
	import springair.domain.swc.digest.RSLScript;

	import org.as3commons.reflect.Type;

	/**
	 * @author a.fell
	 */
	public class TypeGenerationDelegate 
	{
		public function convertSWCObjectToTypeList( swc : RSLSWC, applicationDomain:ApplicationDomain = null ) : Array
		{
			
			var targetDomain:ApplicationDomain = applicationDomain || ApplicationDomain.currentDomain;
			
			var classList : Array = [];
			
			for (var i : int = 0; i < swc.libraries.length; i++) 
			{
				var library : RSLLibrary = swc.libraries[i];
				
				var classID:String;
				
				for each (var script : RSLScript in library.scripts)
				{
					classID = script.definition.id.replace(":", ".");
					
					try
					{
						var clazz:Class = targetDomain.getDefinition(classID) as Class;
						var type:Type = Type.forClass(clazz);
						type && classList.push(type);
					}
					catch(e:Error)
					{
						trace('could not find clazz def', classID);
					}
				}
			}
			
			return classList;
		}
	}
}
